type info struct{ cnt, left, right int }

func findShortestSubArray(nums []int) (result int) {
	infoMap := make(map[int]info)
	for i, v := range nums {
		if element, has := infoMap[v]; has {
			element.cnt++
			element.right = i
			infoMap[v] = element
		} else {
			infoMap[v] = info{1, i, i}
		}
	}
	maxCnt := 0
	for _, v := range infoMap {
		if v.cnt > maxCnt {
			result = v.right - v.left + 1
			maxCnt = v.cnt
		} else if v.cnt == maxCnt {
			result = min(v.right-v.left+1, result)
		}
	}
	return
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}